home *** CD-ROM | disk | FTP | other *** search
-
- I have a winsock app that used to work fine, but I upgraded a couple of
- stacks and the stuff stopped working. Since it happened on two different
- stacks, I figure the problem must be in my code. Maybe I was using a
- marginal practice that an updated stack would not allow. Anyway maybe I
- can get some help here.
-
- The problem has to do with a call to select() on a datagram socket. I am
- implementing a form or RPC (not ONC or DCE or plug in you own acronym) that
- sends a packet to a host and then waits up to two seconds for a reply.
- Don't do it, I see you reaching for that "Just use the async calls..."
- stuff. I really want to do a synchronous function call across the network.
- The call uses select to tell me if any data arrives on the socket.
-
- In the previous versions, this worked quite well. Now the select always
- returns immediately that the fd_set is ready for reading. Of course, I
- then read the socket and the recv_from returns 0 bytes. How can I code
- around this?
-
- I have tried making the socket blocking and non-blocking and the same
- behaviour is displayed. I was thinking maybe I have to just loop on the
- recv_from but then the timing gets tough. I could make a timer callback
- that would set a flag, but that would cost a
- makeprocinstance/settimer/killtimer for every single packet.
-
- I have the code below that makes these calls. Please help if you can. I
- will certainly post the resolution if anybody is interested.
-
- ------- Begin Code Fragment -------------------
-
- // Background stuff.....
- this code uses a UDP socket to receive packets from a server. The packets
- are 608 bytes in size and using a protocol analyzer, I can see them being
- returned to the application. The problem is that the select call below
- returns 1 immediately (not SOCKET_ERROR or 0) even though the packet has not
- yet arrived. The recv_from() does not get any data. We tried all
- combinations of blocking and non-blocking sockets to no avail.
-
-
- cm_recv FAR PASCAL recv_packet( rpc_conv FAR *conv, char FAR *packet, int FAR *size)
- {
- /* Function to receive a response from the server */
-
- struct sockaddr_in sender;
- int len;
- int rc;
- fd_set fdset;
- struct timeval timer;
- char msg_buf[64];
-
- FD_ZERO(&fdset);
- FD_SET(conv->socknum,&fdset);
- timer.tv_sec = 2;
- timer.tv_usec = 0;
- /* to check if any data is available to be read */
- switch ( select( 0, &fdset, NULL, NULL, &timer) ) {
- case 0:
- return RPC_TIMEOUT;
- case SOCKET_ERROR:
- wsprintf(msg_buf,"Select Error, errno = %d",
- WSAGetLastError());
- MessageBox ( NULL, msg_buf,"CM_API",
- MB_ICONASTERISK | MB_OK);
- return RPC_ERROR; /* Some error other than a wouldblock */
- default:
- // Code always takes this path even if no data on the socket
- rc = recvfrom (conv->socknum,
- (LPSTR) packet,
- *size,
- 0, (LPSOCKADDR) &sender, &len);
- *size = rc;
- return RPC_OK;
- }
- }
-
-
- // Code that creates the socket....
-
- cm_bool FAR PASCAL makesocket( rpc_conv FAR *conv, int flag )
- {
- /* Create a socket for communication with the API server */
-
- WSADATA winconfig;
- int socket_error;
- struct hostent FAR *hent;
- char msg_buf[64];
- int localport, rc;
-
- if (flag) {
- /* Startup the winsocket DLL */
- if ((socket_error = WSAStartup( 0x0101, (LPWSADATA) &winconfig)) != 0) {
- wsprintf(msg_buf, "WSAStartup Error, errno = %d", socket_error);
- MessageBox ( NULL, msg_buf, "CM_API", MB_ICONASTERISK | MB_OK);
- return CM_FALSE;
- }
- }
-
- /* Find the UDP server host */
- if ( (hent = gethostbyname( conv->server )) == NULL ) {
- wsprintf(msg_buf, "Cannot locate server %s", (LPSTR)conv->server);
- MessageBox ( NULL, msg_buf, "CM_API", MB_ICONASTERISK | MB_OK);
- return CM_FALSE;
- }
- /* Save the server host in the peer field */
- conv->peer.sin_family=AF_INET;
- conv->peer.sin_addr.s_addr = *( (unsigned long far *) hent->h_addr_list[0]);
- conv->peer.sin_port = htons(CM_RPC_PORT);
-
- /* Create a socket to talk to the server */
- if ( (conv->socknum = socket( AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET ) {
- wsprintf(msg_buf, "Cannot create socket, errno = %d", WSAGetLastError());
- MessageBox ( NULL, msg_buf, "CM_API", MB_ICONASTERISK | MB_OK);
- return CM_FALSE;
- }
-
- /* Set the socket to blocking */
- u_long block_flag = 0;
- if ( ioctlsocket( conv->socknum,
- (long)FIONBIO,
- (unsigned long FAR *)&block_flag) == SOCKET_ERROR ) {
- wsprintf(msg_buf, "Could not make socket blocking, errno = %d",
- WSAGetLastError());
- MessageBox ( NULL, msg_buf, "CM_API", MB_ICONASTERISK | MB_OK);
- return CM_FALSE;
- }
-
-
- _fmemset((void FAR *) &conv->myname, 0x00, sizeof(struct sockaddr_in));
- conv->myname.sin_family=AF_INET;
- conv->myname.sin_addr.s_addr = 0;
-
- for (localport = CM_RPC_PORT; localport < CM_RPC_PORT + MAX_SESSIONS_PC; localport++) {
- conv->myname.sin_port = htons(localport);
- rc = bind ( conv->socknum,
- (struct sockaddr FAR *) &conv->myname,
- sizeof(struct sockaddr_in) );
- if ( rc == 0 ) return CM_TRUE;
- if ( (rc == SOCKET_ERROR) && (WSAGetLastError() != WSAEADDRINUSE) ) {
- wsprintf(msg_buf, "Could not bind name to socket, errno = %d", WSAGetLastError());
- MessageBox ( NULL, msg_buf, "CM_API", MB_ICONASTERISK | MB_OK);
- return CM_FALSE;
- }
- }
- wsprintf(msg_buf, "%s","All Sockets busy, try later.");
- MessageBox ( NULL, msg_buf, "CM_API", MB_ICONASTERISK | MB_OK);
- return CM_FALSE;
- }
- --
- **********************************************************************
- * Mike Vargo | Centigram Communications Corp *
- * | 91 East Tasman Dr. *
- * Internet: mfvargo@netcom.com | San Jose, CA 95134 *
- * Compuserve: 72212,3124 | Telephone: 408-428-3748 *
- **********************************************************************
- From rcq@mailserv-D.ftp.com Wed Mar 23 07:46:42 1994
- Received: from ftp.com (wd40.ftp.com) by SunSITE.Unc.EDU (5.65c+IDA/FvK-1.07) with SMTP
- id AA18411; Wed, 23 Mar 1994 12:47:28 -0500
- Received: from mailserv-D.ftp.com by ftp.com ; Wed, 23 Mar 1994 12:47:23 -0500
- Received: from rcq.oysters.ftp.com by mailserv-D.ftp.com (5.0/SMI-SVR4)
- id AA28641; Wed, 23 Mar 94 12:46:42 EST
- Date: Wed, 23 Mar 94 12:46:42 EST
- Message-Id: <9403231746.AA28641@mailserv-D.ftp.com>
- To: dennyp@sunny.bws.com
- Subject: Re: re. Winsock Providers
- From: rcq@ftp.com (Bob Quinn)
- Reply-To: rcq@ftp.com
- Cc: Multiple recipients of list <winsock@sunsite.unc.edu>
- Sender: rcq@mailserv-D.ftp.com
- Repository: mailserv-D.ftp.com, [message accepted at Wed Mar 23 12:46:32 1994]
- Originating-Client: oysters.ftp.com
- Content-Length: 584
-
- > There may be others but the people that come to mind as WINSOCK.DLL
- > providers are:
- > NetManage Chameloen
- > Novell Lan WorkPlace
- > Beame & Whiteside BW-TCP/BW-NFS
- > Wollongong Group Pathway Access
- > Frontier Technol. Super TCP/IP
-
- There "may" be others? :) I guess it's easy to forget the minor
- players like Microsoft, Sun Microsystems, FTP Software and IBM,
- to name a few.
-
- --
- Bob Quinn rcq@ftp.com
- FTP Software, Inc. No. Andover, MA
-
-